//
//  SSSMerchantBenefitPagerController.m
//  SSSAllRollAgency
//
//  Created by xnxin on 2017/3/15.
//  Copyright (c) 2017 Darker. All rights reserved.
//

#import "SSSMerchantBenefitPagerController.h"
#import "XHKitMacro.h"
#import "XHUIHelper.h"
#import "SSSMerchantTodayBenefitViewController.h"
#import "SSSMerchantHistoryBenefitViewController.h"
#import "UIStoryboard+XHAdd.h"
#import "UIColor+Hexadecimal.h"
#import "UIViewAdditions.h"
#import "SSSMerchantBenefitSearchViewController.h"

@interface SSSMerchantBenefitPagerController ()

@end

@implementation SSSMerchantBenefitPagerController


- (NSArray<NSString *> *)titles {
    return @[@"今日收益", @"历史收益"];
}

- (void)loadView {

    [self initialiseMenu];
    [super loadView];
}

- (void)initialiseMenu {


    CGFloat  padding = 15;
    self.menuHeight = 45;
    self.menuItemWidth = (DEVICE_WIDTH - 2 * padding)/2;
    self.menuViewStyle = WMMenuViewStyleFlood;
    self.menuViewLayoutMode = WMMenuViewLayoutModeCenter;
    self.titleColorNormal = [UIColor whiteColor];
    self.titleSizeNormal = 14;
    self.menuBGColor = [UIColor clearColor];
    self.titleSizeSelected = 14;
    self.titleColorSelected = [UIColor whiteColor];
    self.progressColor = [UIColor colorWithHex:@"55A987"];
    self.progressHeight = 45;
    self.progressViewBottomSpace = 5;
    self.itemMargin = 1;
    self.menuViewBottomSpace = 1;
}

- (void)setupProgressPath {

    CGRect rect = CGRectMake(15, 0, DEVICE_WIDTH - 30, self.menuView.progressView.height);
    UIView *v = [[UIView alloc] initWithFrame:rect];

    UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:v.bounds
                                               byRoundingCorners:UIRectCornerTopLeft|UIRectCornerTopRight
                                                     cornerRadii:CGSizeMake(self.progressViewCornerRadius, self.progressViewCornerRadius)];

    CAShapeLayer * layer = [[CAShapeLayer alloc]init];
    layer.path = path.CGPath;
    layer.frame = v.bounds;
    v.layer.mask = layer;
    v.backgroundColor = [UIColor colorWithHex:@"E6E6E6"];

    [self.menuView insertSubview:v atIndex:0];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.progressViewCornerRadius = 10;
    self.progressViewCorners = UIRectCornerTopLeft|UIRectCornerTopRight;

    self.title = @"店铺收益";
    self.scrollView.backgroundColor = [UIColor clearColor];
    self.viewFrame = CGRectMake(0, 15, DEVICE_WIDTH, self.view.height - 15 - 64 - 44);

    self.navigationItem.rightBarButtonItem = [XHUIHelper navBackButtonWithImage:@"icon_search" target:self action:@selector(enterSearchVC)];
    self.view.backgroundColor = [UIColor colorWithHex:@"F9F9FA"];
    [self setupProgressPath];
}

#pragma mark - action

- (void)enterSearchVC {
    
    
    SSSMerchantBenefitSearchViewController *vc = [SSSMerchantBenefitSearchViewController new];
    [self.navigationController pushViewController:vc animated:true];
    
}

#pragma mark - WMPageCtrl
- (NSInteger)numbersOfChildControllersInPageController:(WMPageController *)pageController {
    return self.titles.count;
}

- (NSString *)pageController:(WMPageController *)pageController titleAtIndex:(NSInteger)index {
    return self.titles[index];
}

- (UIViewController *)pageController:(WMPageController *)pageController
               viewControllerAtIndex:(NSInteger)index
{

    if (index == 0) {
        return [SSSMerchantTodayBenefitViewController new];
    }

    if (index == 1) {
        return [SSSMerchantHistoryBenefitViewController new];
    }

    return nil;
}

@end
